package com.dart.sys.mq.produer.topic;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.JmsException;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Component;

@Component
public class TestTopicSender {
	

	@Autowired
	@Qualifier("jmsTopicTemplate")
	private JmsTemplate jmsTemplate ;
	
	public void send(final String text) {
		
		try {
			this.jmsTemplate.send("test.topic", new MessageCreator() {
				@Override
				public Message createMessage(Session session) throws JMSException {
					System.out.println("发送Topic消息....");
					TextMessage message = session.createTextMessage() ;
					
					message.setText(text);
					
					return message;
				}
			});
		} catch (JmsException e) {
			System.out.println("异常");
		}
	}
	
}
